package com.qk.management.service.impl;

import com.qk.common.PageResult;
import com.qk.entity.Dept;
import com.qk.management.mapper.DeptMapper;
import com.qk.management.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author Enid
 * @date 2025/9/29 10:33
 * @description
 */
@Service
@SuppressWarnings("all")
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;

    @Override
    public void addDept(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.insert(dept);
    }

    /**
     * 查询部门列表
     */

    @Override
    public PageResult<Dept> selectDepts(String name, Integer status, Integer page, Integer pageSize) {
        Integer total = deptMapper.getTotal(name,status);
        Integer offset = (page-1)*pageSize;
        List<Dept> rows = deptMapper.getRows(name,status,offset,pageSize);
        return PageResult.<Dept>builder()
                .total(total)
                .rows(rows)
                .build();
    }
    /**
     * 根据id查询部门
     * @param id
     */

    @Override
    public Dept selectById(Integer id) {
        Dept dept = deptMapper.selectById(id);
        return dept;
    }

    /**
     * 修改部门信息
     */

    @Override
    public void updateDept(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.updateDept(dept);
    }

    @Override
    public void deleteDept(Integer id) {
        deptMapper.deleteDept(id);
    }

    @Override
    public List<Dept> selectAll() {
        List<Dept> all = deptMapper.selectAll();
        return all;
    }
}
